package com.ruoyi.web.controller.carbon;

import com.ruoyi.carbon.domain.XiaoshouDingdan;
import com.ruoyi.carbon.domain.dto.XiaoshouDingdanDto;
import com.ruoyi.carbon.domain.vo.XiaoshouDingdanVo;
import com.ruoyi.carbon.service.XiaoshouDingdanService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("销售订单")
@RestController
@RequestMapping("/carbon/xiaoshouDingdan")
@Anonymous
public class XiaoshouDingdanController extends BaseController {

    @Autowired
    private XiaoshouDingdanService xiaoshouDingdanService;

    @ApiOperation("条件查询")
    @GetMapping("/list")
    public TableDataInfo list( XiaoshouDingdan xiaoshouDingdan) {
        startPage();
        List<XiaoshouDingdan> list = xiaoshouDingdanService.list(xiaoshouDingdan);
        return getDataTable(list);
    }

  /*  @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable Long id) {
        return success(xiaoshouDingdanService.getById(id));
    }*/


    /*@GetMapping("/{id}")
    public AjaxResult getDetailById(@PathVariable Long id) {
        return success(xiaoshouDingdanService.getDetailById(id));
    }*/

    @GetMapping("/{id}")
    public AjaxResult getOrderVo(@PathVariable Long id) {
        return success(xiaoshouDingdanService.getOrderVo(id));
    }



    @PostMapping
    public AjaxResult save(@RequestBody XiaoshouDingdanDto xiaoshouDingdanDto) {

        return toAjax(xiaoshouDingdanService.saveOrUpdate(xiaoshouDingdanDto));
    }


    @DeleteMapping("/{ids}")
    public AjaxResult delete(@PathVariable Long[] ids) {
        return toAjax(xiaoshouDingdanService.delete(ids));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody XiaoshouDingdanDto xiaoshouDingdanDto) {
        int result = xiaoshouDingdanService.saveOrUpdate(xiaoshouDingdanDto);
        return result == 0 ? error() : success();
    }


}
